import java.util.ArrayList;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2024-07-17
 * Time: 11:25
 */
class Solution5 {
    public int lengthOfLIS(int[] nums) {
        int n = nums.length;

        ArrayList<Integer> ret = new ArrayList<>();

        ret.add(nums[0]);

        for(int i = 1; i < n; i++) {
            //边界条件判断
            if(nums[i] > ret.get(ret.size()-1)) {
                ret.add(nums[i]);
            }else {
                //二分查找位置
                int left = 0,right = ret.size()-1;
                while(left < right) {
                    int mid = (left+right)/2;
                    if(ret.get(mid) < nums[i]) {
                        left = mid+1;
                    }else {
                        right = mid;
                    }
                }
                ret.set(left,nums[i]);
            }
        }
        return ret.size();
    }
}